<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="renderer" content="webkit" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>千峰教育大前端Vue教学</title>
  <!-- 引入vue -->
  <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
</head>

<body style="margin:100px;font-size:22px;">
  <!-- 定义一个容器 -->
  <div id="app">
    <!-- 声明模板内容 -->
    <div>
      <div>{{count}}</div>
      <div>{{count1}}</div>
      <div><button @click="count++">count++</button></div>
      <div><button @click="count1++">count1++</button></div>
      <div><button @click="stop">stop</button></div>
    </div>
  </div>
  <script>
    const { createApp, computed, watch, watchEffect, ref } = Vue;
    const app = createApp({
      setup() {
        const count = ref(0);
        const count1 = ref(0);
        const stop = watchEffect((onCleanup) => {
          console.log('=================count.value = ', count.value);
          onCleanup(()=>{
            // 更新的时候先执行这个函数用于清理上一次的副作用，停止监听的时候会执行一次
            console.log('=================onCleanup');
          });
        })
        return { // 返回值会暴露给模板，模板可以直接使用
          count,
          count1,
          stop,
        };
      },
    });
    // 挂载应用
    app.mount('#app');
  </script>
</body>

</html>